//
//  UIViewController+HDChatReply.m
//  app
//
//  Created by D on 15/6/11.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDChatReply.h"
#import "HDChatReplyManager.h"
//#import "HZForumDetialViewController.h"

static const CGFloat kCartTotalPanelHeight = 120;

@interface HDChatReply ()

@property (nonatomic,strong) HDChatReplyManager * replyManager;

@end

@implementation HDChatReply

-(void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"回帖列表";
    self.mutableArray = [NSMutableArray array];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectOf(CGPointMake(0, 64),
                                                                [self.view.ubo fw:UB_WIDTH fh:UB_HEIGHT uh:-kCartTotalPanelHeight oh:+56]) style:UITableViewStyleGrouped];

    self.tableView.backgroundColor = [UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1.0];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:self.tableView];
    
    self.replyManager = [HDChatReplyManager shareManager];

}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.mutableArray = [self.replyManager arrayFromChatReply];
    NSIndexPath *lastRow = [NSIndexPath indexPathForRow:(self.mutableArray.count - 1) inSection:0];
    [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}


#pragma mark - tableView代理
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutableArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString * cellIdentifier = @"cellIdentifier";
    HDChatReplyCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIdentifier];
    if (cell == nil) {
        
        cell = [[HDChatReplyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    cell.delegate = self;
    HDChatReplyModel * model = self.mutableArray[indexPath.row];
    
    [cell cellWithModel:model];
    cell.backgroundView = nil;
    
    
    
    return cell;
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HDChatReplyModel * model = self.mutableArray[indexPath.row];
    if (model.textHeight > 72) {
        return UF(model.textHeight*2+56) ;
    }else{
        return 72;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return UF(10);
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return UF(0.5);
}
//跳转到帖子详情
//-(void)jumpCardWithButton:(HDReplyButton *)button
//{
//    NSDictionary *params = @{@"discuz_id":button.forumd ,@"topic_id":button.card};
//    HZForumDetialViewController *forumVC = [[HZForumDetialViewController alloc] initWithRequestParams:params];
//    forumVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:forumVC animated:YES];
//    
//}

-(void)didReceiveMemoryWarning
{
    
}
@end
